/**
 * cn.ucox.web.framework.servlet.UcoxDispatcherServlet
 *
 * @author chenw
 * @create 16/3/17.22:49
 * @email javacspring@hotmail.com
 */

package cn.com.oceansoft.framework.servlet;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;

/**
 * @author chenw
 * @create 16/3/17 22:49
 * @email javacspring@gmail.com
 */
public class UcoxDispatcherServlet extends DispatcherServlet {

    public UcoxDispatcherServlet(WebApplicationContext webApplicationContext) {
        super(webApplicationContext);
        setThrowExceptionIfNoHandlerFound(true);
    }

    @Override
    protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception {
        super.doService(request, response);
        //        logger.debug("=======postHandle");
        Calendar cal = Calendar.getInstance();
        cal.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));

        SimpleDateFormat greenwichDate = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss 'GMT'", Locale.US);
        greenwichDate.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));

        System.out.println("格林尼治时间：" + greenwichDate.format(cal.getTime()));

        response.setHeader("Last-Modified", greenwichDate.format(cal.getTime())); //Last-Modified:页面的最后生成时间

        cal.setTimeInMillis(cal.getTimeInMillis() + 20000);

        response.setHeader("Expires", greenwichDate.format(cal.getTime())); //Expires:过时期限值
        response.setHeader("Cache-Control", "public"); //Cache-Control来控制页面的缓存与否,public:浏览器和缓存服务器都可以缓存页面信息；
        response.setHeader("Pragma", "Pragma"); //Pragma:设置页面是否缓存，为Pragma则缓存，no-cache则不缓存

    }
}
